Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
vscode-jsonrpc
Advanced tools
The vscode-jsonrpc package provides a framework for implementing JSON-RPC based communication. It is primarily used for building language servers and other tools that need to communicate over JSON-RPC.
Creating a JSON-RPC connection
This code demonstrates how to create a JSON-RPC connection using the vscode-jsonrpc package. It spawns a child process and sets up a message connection using the standard input and output streams of the child process.
const { createMessageConnection, StreamMessageReader, StreamMessageWriter } = require('vscode-jsonrpc');
const { spawn } = require('child_process');
const childProcess = spawn('node', ['path/to/your/server.js']);
const connection = createMessageConnection(
new StreamMessageReader(childProcess.stdout),
new StreamMessageWriter(childProcess.stdin)
);
connection.listen();
Sending a request
This code demonstrates how to send a request over a JSON-RPC connection. The sendRequest method sends a request with a specified method and parameters, and returns a promise that resolves with the response.
connection.sendRequest('example/request', { param1: 'value1' }).then(response => {
console.log('Received response:', response);
});
Handling notifications
This code demonstrates how to handle notifications over a JSON-RPC connection. The onNotification method registers a handler for notifications with a specified method.
connection.onNotification('example/notification', params => {
console.log('Received notification:', params);
});
Handling requests
This code demonstrates how to handle requests over a JSON-RPC connection. The onRequest method registers a handler for requests with a specified method, and the handler returns a response.
connection.onRequest('example/request', params => {
return { result: 'response' };
});
The json-rpc2 package is a JSON-RPC 2.0 implementation for Node.js. It provides similar functionality to vscode-jsonrpc, including creating servers and clients, sending requests, and handling notifications. However, it is a more general-purpose library and does not include some of the higher-level abstractions found in vscode-jsonrpc.
The vscode-languageserver package builds on top of vscode-jsonrpc to provide a framework for implementing language servers. It includes additional features and abstractions specifically for language server development, such as handling text document synchronization and providing language features like completion and hover.
The node-json-rpc package is another JSON-RPC 2.0 implementation for Node.js. It provides basic functionality for creating JSON-RPC servers and clients, sending requests, and handling notifications. It is simpler and more lightweight compared to vscode-jsonrpc, but may lack some of the advanced features and flexibility.
This npm module implements the base messaging protocol spoken between a VSCode language server and a VSCode language client.
The npm module can also be used standalone to establish a JSON-RPC channel between a client and a server. Below an example how to setup a JSON-RPC connection. First the client side.
import * as cp from 'child_process';
import * as rpc from 'vscode-jsonrpc';
let childProcess = cp.spawn(...);
// Use stdin and stdout for communication:
let connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(childProcess.stdout),
new rpc.StreamMessageWriter(childProcess.stdin));
let notification = new rpc.NotificationType<string, void>('testNotification');
connection.listen();
connection.sendNotification(notification, 'Hello World');
The server side looks very symmetrical:
import * as rpc from 'vscode-jsonrpc';
let connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(process.stdin),
new rpc.StreamMessageWriter(process.stdout));
let notification = new rpc.NotificationType<string, void>('testNotification');
connection.onNotification(notification, (param: string) => {
console.log(param); // This prints Hello World
});
connection.listen();
FAQs
A json rpc implementation over streams
The npm package vscode-jsonrpc receives a total of 2,509,476 weekly downloads. As such, vscode-jsonrpc popularity was classified as popular.
We found that vscode-jsonrpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.